package cn.edu.hy.demo09.controller;

import cn.edu.hy.demo09.entity.Product;
import cn.edu.hy.demo09.service.ProductService;
import com.github.monee1988.mybatis.entity.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("product")
public class ProductController {

    private ProductService productService;

    @Autowired
    public void setProductService(ProductService productService) {
        this.productService = productService;
    }

    @GetMapping("index")
    public ModelAndView index(ModelMap modelMap, Product product, HttpServletRequest request){

        modelMap.put("page",productService.findList(product,new Page<Product>(request)));

        return new ModelAndView("demo09/product");
    }

    @GetMapping("buy")
    public ModelAndView buy(ModelMap modelMap,Product product,HttpServletRequest request){

        modelMap.put("buyerFlag",productService.udpateProductInfo(product));

        return new ModelAndView("redirect:index.do");
    }


}
